package cn.org.spring.wechar.service.message;

import cn.org.spring.wechar.constant.EventType;
import cn.org.spring.wechar.event.MessageSource;
import cn.org.spring.wechar.event.listener.ClickListener;
import cn.org.spring.wechar.event.listener.ViewListenter;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 事件消息处理service类
 */
@Service
public class EventMessageService implements IMessage {
    @Override
    public String handler(Map<String, Object> param) {
        MessageSource source = new MessageSource();
        EventType event = EventType.eventType(param.get("Event").toString());
        switch (event) {
            case CLICK:
                source.addListener(new ClickListener());
                break;
            case VIEW:
                source.addListener(new ViewListenter());
                break;
            default:
                //其他事件暂时添加点击事件
                source.addListener(new ClickListener());
                break;
        }
        String s = source.setParam(param);
        System.out.println("事件返回的参数是：" + s);
        return s;
    }
}